Walkthrough 10-1: Explore default error handling

In this walkthrough, you get familiar with the three errors you will learn to handle in this module. You will:

·       Explore information about different types of errors in the Mule Debugger and the console.

·       Review the default error handling behavior.

·       Review and modify the error response settings for an HTTP Listener.

Starting file

If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the solutions folder of the student files ZIP located in the Course Resources.

Create a connectivity error

1.     Return to apdev-flights-ws in Anypoint Studio.

2.     Open config.yaml.

3.     Change the delta.wsdl property from /delta?wsdl to /deltas?wsdl.

4.     Save the file.

5.     Return to implementation.xml and debug the project.

6.     If you get the Errors in Workspace dialog box, click Proceed.

Review a validation error in the Mule Debugger and console

7.     In Advanced REST Client, add a code and make a request to http://localhost:8081/flights?code=FOO.

8.     In the Mule Debugger, step to where the error is thrown and expand the error object; you should see an error description, errorType, and other properties.

 

9.     Step through the rest of the application and review the error information logged in the console.

 

10.  In Advanced REST Client, locate the response status code, status reason, and body; you should see a 500 status code, a status reason of Server Error, and a response body equal to the error description.

 

Review a connectivity error in the Mule Debugger and console

11.  Add an airline and change the code to make a request to http://localhost:8081/flights?airline=delta&code=PDX.

12.  In the Mule Debugger, step to where the error is thrown and review the error object.

13.  Step again and review the error information logged in the console.

14.  Step through the rest of the application.

15.  Return to Advanced REST Client; you should see a 500 Server Error with the error description.

Review a bad request error in the Mule Debugger and console

16.  Change the airline to make a request to http://localhost:8081/flights?airline=american&code=PDX.

17.  In the Mule Debugger, step to where the error is thrown and review the error object.

18.  Step through the rest of the application.

19.  Review the error information logged in the console.

20.  Return to Advanced REST Client; you should see a 500 Server Error with the error description.

21.  Return to Anypoint Studio and switch to the Mule Design perspective.

22.  Stop the project.

Review the default error response settings for an HTTP Listener

23.  Navigate to the properties view for the GET /flights Listener in getFlights.

24.  Select the Responses tab.

25.  Locate the Error Response section and review the default settings for the body, status code, and reason phrase.

 

Remove the default error response settings for the HTTP Listener

26.  Select and cut the body expression (so it has no value, but you can paste it back later).

 

Test the application

27.  Save the file, run the project, and proceed through any errors in the workspace.

28.  In Advanced REST Client, make another request to http://localhost:8081/flights?airline=american&code=PDX; you should get the same response.

Modify the default error response settings for the HTTP Listener

29.  Return to Anypoint Studio.

30.  Return to the Responses tab in the properties view for the GET /flights Listener.

31.  In the error response body, paste back the original value.

output text/plain --- error.description

32.  Change the output type of the error response to application/json and display the error.errorType.

output application/json --- error.errorType

Note: Ensure the error response body is in expression mode.

33.  Set the error response status code to 400.

 

Test the application

34.  Save the file to redeploy the application.

35.  In Advanced REST Client, make another request to http://localhost:8081/flights?airline=american&code=PDX; you should get the new status code and reason and the response body should be the errorType object.

36.  Look at the error namespace and identifier.

 

37.  Change the airline to make a request to http://localhost:8081/flights?airline=delta&code=PDX.

38.  Look at the error namespace and identifier.

 

39.  Change the code to make a request to http://localhost:8081/flights?airline=delta&code=FOO.

40.  Look at the namespace and identifier.

 

Return the default error response settings for the HTTP Listener

41.  Return to Anypoint Studio.

42.  Return to the Responses tab in the properties view for the GET /flights Listener.

43.  Change the error response output type back to text/plain and display the error.description.

output text/plain --- error.description

44.  Remove the status code.

 

Test the application

45.  Save the file to redeploy the application.

46.  In Advanced REST Client, change the airline and code to make a request to http://localhost:8081/flights?airline=american&code=PDX; you should get the 500 Server Error again with the plain text error description.

 

47.  Return to Anypoint Studio.

48.  Stop the project.



Did you complete the walkthrough?

  Yes, I completed the walkthrough

  No, I did not complete the walkthrough

  I completed part of the walkthrough


Comments and/or feedback